{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "69c714b7",
   "metadata": {},
   "source": [
    "# 本周作业：\n",
    "### 尝试创建detect.py 并实现功能调用\n",
    "### 尝试创建analyze.py\\campare.py\\search.py，并实现功能调用\n",
    "### 尝试存放宿舍4位同学的人脸信息到 人脸数据集（XXX栋XXX宿舍）:\n",
    "* 完善faceset信息\n",
    "* 实现人脸搜索和人脸对比，打印结果：是本人 OR 不是本人"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c606f2fd",
   "metadata": {},
   "source": [
    "# 尝试创建detect.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bebe5431",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:02.004003Z",
     "start_time": "2022-03-27T11:53:01.801296Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "API_key = 'wH5jJXa327R2iOJ9TtgHkMXS4WHnfIzj'\n",
    "API_secret = 'APfd1pOaneXua_QcYfmcZEZrXfPfm1BM'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6b9a3fd6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:02.051365Z",
     "start_time": "2022-03-27T11:53:02.023815Z"
    }
   },
   "outputs": [],
   "source": [
    "import detect"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "fb4b706a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:02.083371Z",
     "start_time": "2022-03-27T11:53:02.070371Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module detect:\n",
      "\n",
      "NAME\n",
      "    detect - # Author: lvin\n",
      "\n",
      "FUNCTIONS\n",
      "    face_detect(API_key, API_secret, image_path)\n",
      "        face++ face_detect接口\n",
      "\n",
      "FILE\n",
      "    d:\\api\\week04\\detect.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(detect)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "de4548a9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:03.232263Z",
     "start_time": "2022-03-27T11:53:02.104377Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648381982,7fb539cf-9bed-4e71-9eb9-814307f77459',\n",
       " 'time_used': 622,\n",
       " 'faces': [{'face_token': '8da74b0961215815605e21b31dc12a39',\n",
       "   'face_rectangle': {'top': 257, 'left': 421, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '6641b3c5d8c08ff835b1d9caa31bdbc6',\n",
       "   'face_rectangle': {'top': 197, 'left': 5, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '2850565ef75a92eff62a233056c0dcaf',\n",
       "   'face_rectangle': {'top': 316, 'left': 244, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '5a88449c46d34c3ac59b104d095d9e9b',\n",
       "   'face_rectangle': {'top': 80, 'left': 308, 'width': 35, 'height': 35}},\n",
       "  {'face_token': 'ae83da406c242d1f8835f511f1c1229e',\n",
       "   'face_rectangle': {'top': 374, 'left': 421, 'width': 35, 'height': 35}},\n",
       "  {'face_token': 'b9b9eb149940ecc64002fadb902ff10e',\n",
       "   'face_rectangle': {'top': 20, 'left': 186, 'width': 34, 'height': 34}},\n",
       "  {'face_token': 'ba1fdda3a2dc59b6195a1aa370076af0',\n",
       "   'face_rectangle': {'top': 79, 'left': 422, 'width': 34, 'height': 34}},\n",
       "  {'face_token': '76659997fcfd81dbde76b8ca571642b1',\n",
       "   'face_rectangle': {'top': 316, 'left': 135, 'width': 34, 'height': 34}},\n",
       "  {'face_token': '0e815aae10c4a37f0be49e42500e92bb',\n",
       "   'face_rectangle': {'top': 21, 'left': 130, 'width': 33, 'height': 33}},\n",
       "  {'face_token': 'b2e49fcfe8113718c417ce5f3edbc34a',\n",
       "   'face_rectangle': {'top': 316, 'left': 185, 'width': 33, 'height': 33}},\n",
       "  {'face_token': '2a9f71b1836963d486e21cb68098b218',\n",
       "   'face_rectangle': {'top': 435, 'left': 362, 'width': 33, 'height': 33}},\n",
       "  {'face_token': 'ba4766e619696e23a8c92a58e42e156c',\n",
       "   'face_rectangle': {'top': 258, 'left': 309, 'width': 33, 'height': 33}},\n",
       "  {'face_token': '87bdf724348f226954c3f615ce0601c5',\n",
       "   'face_rectangle': {'top': 20, 'left': 422, 'width': 33, 'height': 33}},\n",
       "  {'face_token': 'd7f1ce225b82b914e9b342e2e4204883',\n",
       "   'face_rectangle': {'top': 197, 'left': 76, 'width': 33, 'height': 33}},\n",
       "  {'face_token': 'ea8bc7b870c838963b9b5ef917cf1e6f',\n",
       "   'face_rectangle': {'top': 198, 'left': 371, 'width': 33, 'height': 33}},\n",
       "  {'face_token': '134ebaee0214ebfd7a5ca50a7556fab5',\n",
       "   'face_rectangle': {'top': 257, 'left': 16, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'fc7d781d87054a6143f94984d4370183',\n",
       "   'face_rectangle': {'top': 377, 'left': 307, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '0ed096e6037a1b4cda5c3bd01eeac0ee',\n",
       "   'face_rectangle': {'top': 140, 'left': 428, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'f906f4a67d631cd6accf4a09f4e979e9',\n",
       "   'face_rectangle': {'top': 81, 'left': 75, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '476269f10551b76d6bbebc048c033093',\n",
       "   'face_rectangle': {'top': 377, 'left': 7, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'bd0a12afe96daf3f0e7c53832a1f82f7',\n",
       "   'face_rectangle': {'top': 199, 'left': 188, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'c11a3adda37a1d5f25f2e1e0ed5055c1',\n",
       "   'face_rectangle': {'top': 318, 'left': 10, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'e1bf8a400a8eeb5d8c9ba9df9d9a7302',\n",
       "   'face_rectangle': {'top': 318, 'left': 72, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'e60ed71c23539487e7336563e7468a79',\n",
       "   'face_rectangle': {'top': 198, 'left': 250, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '1425016c00e4d567056cf5e199b3ba65',\n",
       "   'face_rectangle': {'top': 258, 'left': 370, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '77794408c09b6a32ee64ce4087e46147',\n",
       "   'face_rectangle': {'top': 317, 'left': 309, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'dee69b4fc6b95f7d900ad25a53e6ee1a',\n",
       "   'face_rectangle': {'top': 21, 'left': 373, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '7ec31543fdb86b05c1e1ba6fe767a193',\n",
       "   'face_rectangle': {'top': 140, 'left': 305, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '554905fc6a8dd83bcec557ed2db5252a',\n",
       "   'face_rectangle': {'top': 377, 'left': 132, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '3d4427a04658b4ed1e70cf55bf664014',\n",
       "   'face_rectangle': {'top': 199, 'left': 313, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '72f2eca7cb3240f1c6d0bea124743bd7',\n",
       "   'face_rectangle': {'top': 435, 'left': 194, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '8849170fb29e920b6e61776b7baae4c4',\n",
       "   'face_rectangle': {'top': 376, 'left': 76, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '49c293b9ef2b208dee194a2f6ceb887a',\n",
       "   'face_rectangle': {'top': 80, 'left': 133, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'c31eaadef448497a892e661d66e3cc28',\n",
       "   'face_rectangle': {'top': 436, 'left': 304, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '7411444aa478e34872a60318a991bcee',\n",
       "   'face_rectangle': {'top': 259, 'left': 72, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '9a15f1ca261f2be3a4c22a2f5c198aa5',\n",
       "   'face_rectangle': {'top': 199, 'left': 427, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'ba8a2bc4d0e53d83ad4f20c740efe36e',\n",
       "   'face_rectangle': {'top': 22, 'left': 73, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '3058c6fe5fda0fd6ed0f864bc139f0ac',\n",
       "   'face_rectangle': {'top': 376, 'left': 367, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'd09ae33473e44e2d189065d2ef8e6f54',\n",
       "   'face_rectangle': {'top': 258, 'left': 194, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'aa4deae1dd2158387286641522cabb1b',\n",
       "   'face_rectangle': {'top': 377, 'left': 192, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'd777ebef6105909e0e9f6bb262a01a8d',\n",
       "   'face_rectangle': {'top': 436, 'left': 428, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'c972a87ba939b741c3ef182e150ea1f4',\n",
       "   'face_rectangle': {'top': 199, 'left': 131, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'f18d2ff3d5230d5730fa9c5a5deebe27',\n",
       "   'face_rectangle': {'top': 319, 'left': 365, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '0691ed0f82b05c9974336f2111c7a3c8',\n",
       "   'face_rectangle': {'top': 377, 'left': 251, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '65b9ddb6a472717af4fcbef202eca6f8',\n",
       "   'face_rectangle': {'top': 437, 'left': 14, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '1f715be4d2136f50c2178fcc0b6607d5',\n",
       "   'face_rectangle': {'top': 140, 'left': 72, 'width': 30, 'height': 30}},\n",
       "  {'face_token': '1e638d2528fffda5922d283861e83bb0',\n",
       "   'face_rectangle': {'top': 80, 'left': 252, 'width': 30, 'height': 30}},\n",
       "  {'face_token': 'c677c3730fda4da6f51ae1887db82bac',\n",
       "   'face_rectangle': {'top': 23, 'left': 251, 'width': 30, 'height': 30}},\n",
       "  {'face_token': 'aef49732f19f85e6073fad7395d45310',\n",
       "   'face_rectangle': {'top': 258, 'left': 252, 'width': 30, 'height': 30}},\n",
       "  {'face_token': 'd12b7bc00ac3bf68fe13e3de4001f4b9',\n",
       "   'face_rectangle': {'top': 318, 'left': 426, 'width': 30, 'height': 30}}],\n",
       " 'image_id': 'bezQ9W4DwND6mLX989LGHA==',\n",
       " 'face_num': 50}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_secret,'face.jfif')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "68b6cafd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:04.246771Z",
     "start_time": "2022-03-27T11:53:03.251248Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'e2332c8dff81d3528251048d1e00faba'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_tokens = detect.face_detect(API_key,API_secret,'face.jfif')[\"faces\"][0][\"face_token\"]\n",
    "face_tokens"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de1d0e17",
   "metadata": {},
   "source": [
    "# 尝试创建analyze.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f2417f18",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:04.277798Z",
     "start_time": "2022-03-27T11:53:04.264776Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "API_key = 'wH5jJXa327R2iOJ9TtgHkMXS4WHnfIzj'\n",
    "API_secret = 'APfd1pOaneXua_QcYfmcZEZrXfPfm1BM'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "1d948149",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:04.324790Z",
     "start_time": "2022-03-27T11:53:04.295785Z"
    }
   },
   "outputs": [],
   "source": [
    "import analyze"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "23ecdec0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:04.356799Z",
     "start_time": "2022-03-27T11:53:04.344794Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module analyze:\n",
      "\n",
      "NAME\n",
      "    analyze - # Author: lvin\n",
      "\n",
      "FUNCTIONS\n",
      "    face_analyze(API_key, API_secret, face_tokens, landmark=1, attributes=None, face_rectangle=None, beauty_score_min=0, beauty_score_max=100)\n",
      "        face++ face_analyze接口\n",
      "\n",
      "FILE\n",
      "    d:\\api\\week04\\analyze.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(analyze)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "aa167725",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:04.716472Z",
     "start_time": "2022-03-27T11:53:04.375801Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'time_used': 80,\n",
       " 'request_id': '1648381984,7362c5b7-94db-49d1-98ff-7d0ea5196e31',\n",
       " 'faces': [{'landmark': {'mouth_upper_lip_left_contour2': {'y': 280, 'x': 443},\n",
       "    'mouth_upper_lip_top': {'y': 279, 'x': 447},\n",
       "    'mouth_upper_lip_left_contour1': {'y': 279, 'x': 446},\n",
       "    'left_eye_upper_left_quarter': {'y': 263, 'x': 435},\n",
       "    'left_eyebrow_lower_middle': {'y': 259, 'x': 437},\n",
       "    'mouth_upper_lip_left_contour3': {'y': 281, 'x': 444},\n",
       "    'right_eye_top': {'y': 263, 'x': 451},\n",
       "    'left_eye_bottom': {'y': 266, 'x': 437},\n",
       "    'right_eyebrow_lower_left_quarter': {'y': 261, 'x': 451},\n",
       "    'right_eye_pupil': {'y': 264, 'x': 450},\n",
       "    'mouth_lower_lip_right_contour1': {'y': 281, 'x': 449},\n",
       "    'mouth_lower_lip_right_contour3': {'y': 284, 'x': 448},\n",
       "    'mouth_lower_lip_right_contour2': {'y': 283, 'x': 450},\n",
       "    'contour_chin': {'y': 292, 'x': 446},\n",
       "    'contour_left9': {'y': 292, 'x': 441},\n",
       "    'left_eye_lower_right_quarter': {'y': 265, 'x': 439},\n",
       "    'mouth_lower_lip_top': {'y': 281, 'x': 447},\n",
       "    'right_eyebrow_upper_middle': {'y': 258, 'x': 453},\n",
       "    'left_eyebrow_left_corner': {'y': 260, 'x': 430},\n",
       "    'right_eye_bottom': {'y': 266, 'x': 452},\n",
       "    'contour_left7': {'y': 289, 'x': 432},\n",
       "    'contour_left6': {'y': 286, 'x': 428},\n",
       "    'contour_left5': {'y': 283, 'x': 425},\n",
       "    'contour_left4': {'y': 278, 'x': 424},\n",
       "    'contour_left3': {'y': 274, 'x': 423},\n",
       "    'contour_left2': {'y': 269, 'x': 422},\n",
       "    'contour_left1': {'y': 265, 'x': 422},\n",
       "    'left_eye_lower_left_quarter': {'y': 265, 'x': 435},\n",
       "    'contour_right1': {'y': 265, 'x': 455},\n",
       "    'contour_right3': {'y': 271, 'x': 456},\n",
       "    'contour_right2': {'y': 268, 'x': 455},\n",
       "    'mouth_left_corner': {'y': 281, 'x': 440},\n",
       "    'contour_right4': {'y': 274, 'x': 455},\n",
       "    'contour_right7': {'y': 284, 'x': 452},\n",
       "    'right_eyebrow_left_corner': {'y': 261, 'x': 450},\n",
       "    'nose_right': {'y': 273, 'x': 451},\n",
       "    'nose_tip': {'y': 273, 'x': 449},\n",
       "    'contour_right5': {'y': 277, 'x': 455},\n",
       "    'nose_contour_lower_middle': {'y': 275, 'x': 448},\n",
       "    'left_eyebrow_lower_left_quarter': {'y': 259, 'x': 433},\n",
       "    'mouth_lower_lip_left_contour3': {'y': 284, 'x': 444},\n",
       "    'right_eye_right_corner': {'y': 265, 'x': 454},\n",
       "    'right_eye_lower_right_quarter': {'y': 265, 'x': 453},\n",
       "    'mouth_upper_lip_right_contour2': {'y': 280, 'x': 450},\n",
       "    'right_eyebrow_lower_right_quarter': {'y': 260, 'x': 455},\n",
       "    'left_eye_left_corner': {'y': 264, 'x': 433},\n",
       "    'mouth_right_corner': {'y': 281, 'x': 450},\n",
       "    'mouth_upper_lip_right_contour3': {'y': 281, 'x': 449},\n",
       "    'right_eye_lower_left_quarter': {'y': 266, 'x': 450},\n",
       "    'left_eyebrow_right_corner': {'y': 260, 'x': 443},\n",
       "    'left_eyebrow_lower_right_quarter': {'y': 260, 'x': 440},\n",
       "    'right_eye_center': {'y': 265, 'x': 451},\n",
       "    'nose_left': {'y': 274, 'x': 442},\n",
       "    'mouth_lower_lip_left_contour1': {'y': 281, 'x': 444},\n",
       "    'left_eye_upper_right_quarter': {'y': 263, 'x': 439},\n",
       "    'right_eyebrow_lower_middle': {'y': 260, 'x': 453},\n",
       "    'left_eye_top': {'y': 263, 'x': 437},\n",
       "    'left_eye_center': {'y': 264, 'x': 437},\n",
       "    'contour_left8': {'y': 291, 'x': 436},\n",
       "    'contour_right9': {'y': 290, 'x': 449},\n",
       "    'right_eye_left_corner': {'y': 265, 'x': 449},\n",
       "    'mouth_lower_lip_bottom': {'y': 284, 'x': 447},\n",
       "    'left_eyebrow_upper_left_quarter': {'y': 258, 'x': 433},\n",
       "    'left_eye_pupil': {'y': 264, 'x': 436},\n",
       "    'right_eyebrow_upper_left_quarter': {'y': 259, 'x': 451},\n",
       "    'contour_right8': {'y': 287, 'x': 451},\n",
       "    'right_eyebrow_right_corner': {'y': 260, 'x': 456},\n",
       "    'right_eye_upper_left_quarter': {'y': 264, 'x': 450},\n",
       "    'left_eyebrow_upper_middle': {'y': 257, 'x': 437},\n",
       "    'right_eyebrow_upper_right_quarter': {'y': 259, 'x': 455},\n",
       "    'nose_contour_left1': {'y': 265, 'x': 443},\n",
       "    'nose_contour_left2': {'y': 271, 'x': 443},\n",
       "    'mouth_upper_lip_right_contour1': {'y': 279, 'x': 449},\n",
       "    'nose_contour_right1': {'y': 265, 'x': 448},\n",
       "    'nose_contour_right2': {'y': 271, 'x': 450},\n",
       "    'mouth_lower_lip_left_contour2': {'y': 283, 'x': 442},\n",
       "    'contour_right6': {'y': 281, 'x': 454},\n",
       "    'nose_contour_right3': {'y': 275, 'x': 450},\n",
       "    'nose_contour_left3': {'y': 275, 'x': 445},\n",
       "    'left_eye_right_corner': {'y': 265, 'x': 441},\n",
       "    'left_eyebrow_upper_right_quarter': {'y': 258, 'x': 440},\n",
       "    'right_eye_upper_right_quarter': {'y': 264, 'x': 453},\n",
       "    'mouth_upper_lip_bottom': {'y': 281, 'x': 447}},\n",
       "   'face_rectangle': {'width': 35, 'top': 257, 'left': 421, 'height': 35},\n",
       "   'face_token': 'e2332c8dff81d3528251048d1e00faba'}]}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "analyze.face_analyze(API_key,API_secret,face_tokens)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12e1844a",
   "metadata": {},
   "source": [
    "# 尝试创建compare.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "6e1c1c8a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:05.541112Z",
     "start_time": "2022-03-27T11:53:04.735475Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648381985,1e6948ab-4b74-4458-981c-57a18d0f1418',\n",
       " 'time_used': 444,\n",
       " 'faces': [{'face_token': '9e234d5819eb29d09c39e8973c94c575',\n",
       "   'face_rectangle': {'top': 257, 'left': 421, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '76c6049a9517bcd8f5c8d02335376f94',\n",
       "   'face_rectangle': {'top': 197, 'left': 5, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '062ac6fa9dff22011e2f04e45746abe5',\n",
       "   'face_rectangle': {'top': 316, 'left': 244, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '22cb1cee026dd7205d7c819e6a906681',\n",
       "   'face_rectangle': {'top': 80, 'left': 308, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '238461761a50a188ad71ed7681649fb8',\n",
       "   'face_rectangle': {'top': 374, 'left': 421, 'width': 35, 'height': 35}},\n",
       "  {'face_token': '4b1c3db8b02279ea2e59a3d3951d1287',\n",
       "   'face_rectangle': {'top': 20, 'left': 186, 'width': 34, 'height': 34}},\n",
       "  {'face_token': '90959b780b42b85b3895fdf79841d773',\n",
       "   'face_rectangle': {'top': 79, 'left': 422, 'width': 34, 'height': 34}},\n",
       "  {'face_token': '63ae71a037d7d194999527ceb452436f',\n",
       "   'face_rectangle': {'top': 316, 'left': 135, 'width': 34, 'height': 34}},\n",
       "  {'face_token': '961e985c5a3a22e415fd806c6d9d2f56',\n",
       "   'face_rectangle': {'top': 21, 'left': 130, 'width': 33, 'height': 33}},\n",
       "  {'face_token': '4907a089dcf8e60e595a673b40c4fb93',\n",
       "   'face_rectangle': {'top': 316, 'left': 185, 'width': 33, 'height': 33}},\n",
       "  {'face_token': 'fa74e3975082ee1f870bbf9a97b60d4a',\n",
       "   'face_rectangle': {'top': 435, 'left': 362, 'width': 33, 'height': 33}},\n",
       "  {'face_token': '9749f44ce459e72bfa489220f50824ba',\n",
       "   'face_rectangle': {'top': 258, 'left': 309, 'width': 33, 'height': 33}},\n",
       "  {'face_token': '856d5e14a5a094e391b52d6c2741351d',\n",
       "   'face_rectangle': {'top': 20, 'left': 422, 'width': 33, 'height': 33}},\n",
       "  {'face_token': 'dfadc280c6a892014950b76cf62b13a0',\n",
       "   'face_rectangle': {'top': 197, 'left': 76, 'width': 33, 'height': 33}},\n",
       "  {'face_token': '581f2934c8c727bcc963c91d057c7383',\n",
       "   'face_rectangle': {'top': 198, 'left': 371, 'width': 33, 'height': 33}},\n",
       "  {'face_token': 'ec6ab35239fb3cf01b61985286219909',\n",
       "   'face_rectangle': {'top': 257, 'left': 16, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '9fba15b28601a3bbbcc45cd8717f0ac6',\n",
       "   'face_rectangle': {'top': 377, 'left': 307, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '90c0035d9020a129bd0a734c6a558390',\n",
       "   'face_rectangle': {'top': 140, 'left': 428, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '4b2e6eee638ec59c06f2dba224beb53b',\n",
       "   'face_rectangle': {'top': 81, 'left': 75, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'ea1807d2044a4d7ac0cc7d3b73ad74fc',\n",
       "   'face_rectangle': {'top': 377, 'left': 7, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '52ec152682e7599657fb281658c6c1f9',\n",
       "   'face_rectangle': {'top': 199, 'left': 188, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '0a3bb2c49aebeecc98db6851ab4ae6c2',\n",
       "   'face_rectangle': {'top': 318, 'left': 10, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '6ecbacfe7699a7a10a180bd125420319',\n",
       "   'face_rectangle': {'top': 318, 'left': 72, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '1fdc467533d19c2efe7422145f892361',\n",
       "   'face_rectangle': {'top': 198, 'left': 250, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '8a04c2b6f7c99ff1163d860039629406',\n",
       "   'face_rectangle': {'top': 258, 'left': 370, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '2fa8ebb312463d87f862b2485892ed6b',\n",
       "   'face_rectangle': {'top': 317, 'left': 309, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '0e13c80c2bdcec2a03c0968996027146',\n",
       "   'face_rectangle': {'top': 21, 'left': 373, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '3187d8f9ea74766550a3638beb33dbda',\n",
       "   'face_rectangle': {'top': 140, 'left': 305, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '1c554a5cc2d16caae24dd9d312b641df',\n",
       "   'face_rectangle': {'top': 377, 'left': 132, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '72705b15a3e82ea14a148c9c42e74d05',\n",
       "   'face_rectangle': {'top': 199, 'left': 313, 'width': 32, 'height': 32}},\n",
       "  {'face_token': 'bdbeac8c8223a9f0e77c9ebea2fd2fe1',\n",
       "   'face_rectangle': {'top': 435, 'left': 194, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '6ddab76a57a63669c9948ba67f68a143',\n",
       "   'face_rectangle': {'top': 376, 'left': 76, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '94d15a332bfc5585df2dcdd551c41ec0',\n",
       "   'face_rectangle': {'top': 80, 'left': 133, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '2c3a29e44ac332a1431974fcef19e70c',\n",
       "   'face_rectangle': {'top': 436, 'left': 304, 'width': 32, 'height': 32}},\n",
       "  {'face_token': '662a7a4f6a47abc08593d943ee05ef5c',\n",
       "   'face_rectangle': {'top': 259, 'left': 72, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'a7ff3b38e972379857af613acdee1837',\n",
       "   'face_rectangle': {'top': 199, 'left': 427, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '01bbcac66c92606bc0df61c7ed1f6940',\n",
       "   'face_rectangle': {'top': 22, 'left': 73, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '479b6b6c5818246cf994e5afaecbff73',\n",
       "   'face_rectangle': {'top': 376, 'left': 367, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'aafce4f152f78d95c16383794a396c53',\n",
       "   'face_rectangle': {'top': 258, 'left': 194, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '255585e31937f12b89941c17d7b33505',\n",
       "   'face_rectangle': {'top': 377, 'left': 192, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '05bdfcb606b716db8a87a935ee2e85fb',\n",
       "   'face_rectangle': {'top': 436, 'left': 428, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '1609b0a87c04d0f68e7312f6781f1536',\n",
       "   'face_rectangle': {'top': 199, 'left': 131, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '8a8bf181a129aa195f248ce33af1d91a',\n",
       "   'face_rectangle': {'top': 319, 'left': 365, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '2a95005e8130ab6eeeb99c10f46a9858',\n",
       "   'face_rectangle': {'top': 377, 'left': 251, 'width': 31, 'height': 31}},\n",
       "  {'face_token': 'd723499dd73885e6d8297390e60fe0dc',\n",
       "   'face_rectangle': {'top': 437, 'left': 14, 'width': 31, 'height': 31}},\n",
       "  {'face_token': '3cd13499d2756db8e7eb1ca9ac18c4cd',\n",
       "   'face_rectangle': {'top': 140, 'left': 72, 'width': 30, 'height': 30}},\n",
       "  {'face_token': '56b111c8e034bab3777f8e7a3ea4d44e',\n",
       "   'face_rectangle': {'top': 80, 'left': 252, 'width': 30, 'height': 30}},\n",
       "  {'face_token': '06644d6da1dddf34e473ee8705f8b6e5',\n",
       "   'face_rectangle': {'top': 23, 'left': 251, 'width': 30, 'height': 30}},\n",
       "  {'face_token': '98a645565cb1deef93329df1474fc24d',\n",
       "   'face_rectangle': {'top': 258, 'left': 252, 'width': 30, 'height': 30}},\n",
       "  {'face_token': '9f73f849b47e80a1530a278c8eaac4bf',\n",
       "   'face_rectangle': {'top': 318, 'left': 426, 'width': 30, 'height': 30}}],\n",
       " 'image_id': 'bezQ9W4DwND6mLX989LGHA==',\n",
       " 'face_num': 50}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_secret,'face.jfif')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e5fce1ef",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:06.511430Z",
     "start_time": "2022-03-27T11:53:05.560117Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1a7a11b24e1c4b4fb86c2d665cb53c81'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token1 = detect.face_detect(API_key,API_secret,'face.jfif')[\"faces\"][0][\"face_token\"]\n",
    "face_token1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "aebc5766",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:06.892447Z",
     "start_time": "2022-03-27T11:53:06.529432Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648381986,396a5d90-809d-4d8e-adc7-d2c382e05abe',\n",
       " 'time_used': 34,\n",
       " 'faces': [{'face_token': '8b0f48b3524180d5149fdfbc726698ff',\n",
       "   'face_rectangle': {'top': 108, 'left': 141, 'width': 107, 'height': 107}}],\n",
       " 'image_id': 'JoYdaZ0h1hGb4ih1d2EZVw==',\n",
       " 'face_num': 1}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "detect.face_detect(API_key,API_secret,'liu.jfif')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "fc4c346c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:07.267719Z",
     "start_time": "2022-03-27T11:53:06.916452Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1690d4f6c0c97062937a097f4f2421de'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token2 = detect.face_detect(API_key,API_secret,'liu.jfif')[\"faces\"][0][\"face_token\"]\n",
    "face_token2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "706b3e60",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:07.299730Z",
     "start_time": "2022-03-27T11:53:07.287730Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "API_key = 'wH5jJXa327R2iOJ9TtgHkMXS4WHnfIzj'\n",
    "API_secret = 'APfd1pOaneXua_QcYfmcZEZrXfPfm1BM'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7988068c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:07.331639Z",
     "start_time": "2022-03-27T11:53:07.318638Z"
    }
   },
   "outputs": [],
   "source": [
    "import compare"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b4661620",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:07.411658Z",
     "start_time": "2022-03-27T11:53:07.371649Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module compare:\n",
      "\n",
      "NAME\n",
      "    compare - # Author: lvin\n",
      "\n",
      "FUNCTIONS\n",
      "    face_compare(API_key, API_secret, face_token_01, face_token_02)\n",
      "        face++ face_compare函数\n",
      "\n",
      "FILE\n",
      "    d:\\api\\week04\\compare.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(compare)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "57eeb2f7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:07.933521Z",
     "start_time": "2022-03-27T11:53:07.431662Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648381987,620c4e5e-a933-4c26-b392-8f6c58f3c090',\n",
       " 'time_used': 266,\n",
       " 'confidence': 35.785,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "compare.face_compare(API_key,API_secret,face_token1,face_token2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "844c5e21",
   "metadata": {},
   "source": [
    "# 尝试创建search.py 并实现功能调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "2c3aed8c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:08.952495Z",
     "start_time": "2022-03-27T11:53:07.953528Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'fb7d38c72fda9be0a60373eb3dfc181f'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_token = detect.face_detect(API_key,API_secret,'face.jfif')[\"faces\"][0][\"face_token\"]\n",
    "face_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2d9058ae",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:09.294893Z",
     "start_time": "2022-03-27T11:53:08.972485Z"
    }
   },
   "outputs": [],
   "source": [
    "API_key = 'wH5jJXa327R2iOJ9TtgHkMXS4WHnfIzj'\n",
    "API_secret = 'APfd1pOaneXua_QcYfmcZEZrXfPfm1BM'\n",
    "\n",
    "FaceSet_url = 'https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets'\n",
    "payload = {\n",
    "    'api_key':API_key,\n",
    "    'api_secret':API_secret\n",
    "}\n",
    "\n",
    "r = requests.post(url = FaceSet_url, params = payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "d5d00ce2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:09.326906Z",
     "start_time": "2022-03-27T11:53:09.313904Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '10d47cc40e583334e05b0ab49dca9fe3',\n",
       " 'outer_id': '',\n",
       " 'display_name': '',\n",
       " 'tags': ''}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()['facesets'][-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7e276d8f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:09.357908Z",
     "start_time": "2022-03-27T11:53:09.345907Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'10d47cc40e583334e05b0ab49dca9fe3'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "faceset_token = r.json()['facesets'][-1]['faceset_token']\n",
    "faceset_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "16fe519b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:09.388913Z",
     "start_time": "2022-03-27T11:53:09.376917Z"
    }
   },
   "outputs": [],
   "source": [
    "import requests\n",
    "API_key = 'wH5jJXa327R2iOJ9TtgHkMXS4WHnfIzj'\n",
    "API_secret = 'APfd1pOaneXua_QcYfmcZEZrXfPfm1BM'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "a0866772",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:09.437909Z",
     "start_time": "2022-03-27T11:53:09.407900Z"
    }
   },
   "outputs": [],
   "source": [
    "import search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "26e60679",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:09.468915Z",
     "start_time": "2022-03-27T11:53:09.456911Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module search:\n",
      "\n",
      "NAME\n",
      "    search - # Author: lvin\n",
      "\n",
      "FUNCTIONS\n",
      "    face_search(API_key, API_secret, face_token, faceset_token)\n",
      "        face++ face_search接口\n",
      "\n",
      "FILE\n",
      "    d:\\api\\week04\\search.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(search)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4ad94485",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-27T11:53:10.092409Z",
     "start_time": "2022-03-27T11:53:09.488918Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'request_id': '1648381989,e89907df-3098-40d1-bbb4-fab716675cf8',\n",
       " 'time_used': 318,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'results': [{'confidence': 97.204,\n",
       "   'user_id': '',\n",
       "   'face_token': 'f5ee1d3f20943c8951c27844819e625b'}]}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "search.face_search(API_key,API_secret,face_token,faceset_token)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6ff9231",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00eb4e4c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "998af591",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83aeb5b0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
